/*
* File :
* Created : 14 janv. 07
* By : eSpider Team
* Version : $Revision$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details ( see the LICENSE file ).
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package org.fbmc.server;

import org.apache.jasper.servlet.JspServlet;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.DefaultServlet;
import org.mortbay.jetty.servlet.ServletHolder;

public class EmbeddedJettyServer extends Server implements EmbeddedServer {
	
	public EmbeddedJettyServer() throws EmbeddedServerException {
		super();
		
		try{
			//Ecoute les requetes HTTP
			Connector connector = new SelectChannelConnector();
			connector.setPort(8080);
			setConnectors(new Connector[]{connector});
			
			Context context = new Context(this, "/", Context.SESSIONS);
			context.setResourceBase("./web");		
			context.addServlet(new ServletHolder(new DefaultServlet()), "/");
			context.addServlet(new ServletHolder(new JspServlet()), "*.jsp");
			
			setStopAtShutdown(true);
					
			start();
		}catch(Exception e){
			throw new EmbeddedServerException("Jetty", e.getLocalizedMessage());
		}
	}

	public void shutdown() {
		try{
			stop();
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 